﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;

namespace HslCommunication.Controls
{
	/// <summary>
	/// 一个开关按钮类
	/// </summary>
	// Token: 0x02000179 RID: 377
	[DefaultEvent("Click")]
	public class UserSwitch : UserControl
	{
		/// <summary>
		/// 实例化一个开关按钮对象
		/// </summary>
		// Token: 0x06001F08 RID: 7944 RVA: 0x00096B1C File Offset: 0x00094D1C
		public UserSwitch()
		{
			this.InitializeComponent();
			this.DoubleBuffered = true;
			this.brush_switch_background = new SolidBrush(this.color_switch_background);
			this.pen_switch_background = new Pen(this.color_switch_background, 2f);
			this.brush_switch_foreground = new SolidBrush(this.color_switch_foreground);
			this.centerFormat = new StringFormat();
			this.centerFormat.Alignment = StringAlignment.Center;
			this.centerFormat.LineAlignment = StringAlignment.Center;
		}

		// Token: 0x06001F09 RID: 7945 RVA: 0x00009AA1 File Offset: 0x00007CA1
		private void UserSwitch_Load(object sender, EventArgs e)
		{
		}

		// Token: 0x06001F0A RID: 7946 RVA: 0x00096C00 File Offset: 0x00094E00
		private void UserSwitch_Paint(object sender, PaintEventArgs e)
		{
			bool flag = !Authorization.nzugaydgwadawdibbas();
			if (!flag)
			{
				e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
				e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
				Point centerPoint = this.GetCenterPoint();
				e.Graphics.TranslateTransform((float)centerPoint.X, (float)centerPoint.Y);
				int num = 45 * (centerPoint.X * 2 - 30) / 130;
				bool flag2 = num < 5;
				if (!flag2)
				{
					Rectangle rect = new Rectangle(-num - 4, -num - 4, 2 * num + 8, 2 * num + 8);
					Rectangle rect2 = new Rectangle(-num, -num, 2 * num, 2 * num);
					e.Graphics.DrawEllipse(this.pen_switch_background, rect);
					e.Graphics.FillEllipse(this.brush_switch_background, rect2);
					float angle = -36f;
					bool switchStatus = this.SwitchStatus;
					if (switchStatus)
					{
						angle = 36f;
					}
					e.Graphics.RotateTransform(angle);
					int num2 = 20 * (centerPoint.X * 2 - 30) / 130;
					Rectangle rect3 = new Rectangle(-centerPoint.X / 8, -num - num2, centerPoint.X / 4, num * 2 + num2 * 2);
					e.Graphics.FillRectangle(this.brush_switch_foreground, rect3);
					Rectangle rect4 = new Rectangle(-centerPoint.X / 16, -num - 10, centerPoint.X / 8, centerPoint.X * 3 / 8);
					e.Graphics.FillEllipse(this.SwitchStatus ? Brushes.LimeGreen : Brushes.Tomato, rect4);
					Rectangle r = new Rectangle(-50, -num - num2 - 15, 100, 15);
					e.Graphics.DrawString(this.SwitchStatus ? this.description[1] : this.description[0], this.Font, this.SwitchStatus ? Brushes.LimeGreen : Brushes.Tomato, r, this.centerFormat);
					e.Graphics.ResetTransform();
				}
			}
		}

		/// <summary>
		/// 开关按钮发生变化的事件
		/// </summary>
		// Token: 0x1400003E RID: 62
		// (add) Token: 0x06001F0B RID: 7947 RVA: 0x00096E08 File Offset: 0x00095008
		// (remove) Token: 0x06001F0C RID: 7948 RVA: 0x00096E40 File Offset: 0x00095040
		[Category("操作")]
		[Description("点击了按钮开发后触发")]
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		public event Action<object, bool> OnSwitchChanged;

		// Token: 0x06001F0D RID: 7949 RVA: 0x00096E78 File Offset: 0x00095078
		private Point GetCenterPoint()
		{
			bool flag = base.Height > base.Width;
			Point result;
			if (flag)
			{
				result = new Point(base.Width / 2, base.Width / 2);
			}
			else
			{
				result = new Point(base.Height / 2, base.Height / 2);
			}
			return result;
		}

		/// <summary>
		/// 获取或设置开关按钮的背景色
		/// </summary>
		// Token: 0x17000669 RID: 1641
		// (get) Token: 0x06001F0E RID: 7950 RVA: 0x00096ECC File Offset: 0x000950CC
		// (set) Token: 0x06001F0F RID: 7951 RVA: 0x00096EE4 File Offset: 0x000950E4
		[Browsable(true)]
		[Description("获取或设置开关按钮的背景色")]
		[Category("外观")]
		[DefaultValue(typeof(Color), "DimGray")]
		public Color SwitchBackground
		{
			get
			{
				return this.color_switch_background;
			}
			set
			{
				this.color_switch_background = value;
				Brush brush = this.brush_switch_background;
				if (brush != null)
				{
					brush.Dispose();
				}
				Pen pen = this.pen_switch_background;
				if (pen != null)
				{
					pen.Dispose();
				}
				this.brush_switch_background = new SolidBrush(this.color_switch_background);
				this.pen_switch_background = new Pen(this.color_switch_background, 2f);
				base.Invalidate();
			}
		}

		/// <summary>
		/// 获取或设置开关按钮的前景色
		/// </summary>
		// Token: 0x1700066A RID: 1642
		// (get) Token: 0x06001F10 RID: 7952 RVA: 0x00096F4C File Offset: 0x0009514C
		// (set) Token: 0x06001F11 RID: 7953 RVA: 0x00096F64 File Offset: 0x00095164
		[Browsable(true)]
		[Description("获取或设置开关按钮的前景色")]
		[Category("外观")]
		[DefaultValue(typeof(Color), "[36, 36, 36]")]
		public Color SwitchForeground
		{
			get
			{
				return this.color_switch_foreground;
			}
			set
			{
				this.color_switch_foreground = value;
				this.brush_switch_foreground = new SolidBrush(this.color_switch_foreground);
				base.Invalidate();
			}
		}

		/// <summary>
		/// 获取或设置开关按钮的开合状态
		/// </summary>
		// Token: 0x1700066B RID: 1643
		// (get) Token: 0x06001F12 RID: 7954 RVA: 0x00096F88 File Offset: 0x00095188
		// (set) Token: 0x06001F13 RID: 7955 RVA: 0x00096FA0 File Offset: 0x000951A0
		[Browsable(true)]
		[Description("获取或设置开关按钮的开合状态")]
		[Category("外观")]
		[DefaultValue(false)]
		public bool SwitchStatus
		{
			get
			{
				return this.switch_status;
			}
			set
			{
				bool flag = value != this.switch_status;
				if (flag)
				{
					this.switch_status = value;
					base.Invalidate();
					Action<object, bool> onSwitchChanged = this.OnSwitchChanged;
					if (onSwitchChanged != null)
					{
						onSwitchChanged(this, this.switch_status);
					}
				}
			}
		}

		/// <summary>
		/// 获取或设置两种开关状态的文本描述，例如：new string[]{"Off","On"}
		/// </summary>
		// Token: 0x1700066C RID: 1644
		// (get) Token: 0x06001F14 RID: 7956 RVA: 0x00096FE8 File Offset: 0x000951E8
		// (set) Token: 0x06001F15 RID: 7957 RVA: 0x00097000 File Offset: 0x00095200
		[Browsable(false)]
		public string[] SwitchStatusDescription
		{
			get
			{
				return this.description;
			}
			set
			{
				bool flag = value != null && value.Length == 2;
				if (flag)
				{
					this.description = value;
				}
			}
		}

		// Token: 0x06001F16 RID: 7958 RVA: 0x00097027 File Offset: 0x00095227
		private void UserSwitch_Click(object sender, EventArgs e)
		{
			this.SwitchStatus = !this.SwitchStatus;
		}

		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		/// <param name="disposing">如果应释放托管资源，为 true；否则为 false。</param>
		// Token: 0x06001F17 RID: 7959 RVA: 0x0009703C File Offset: 0x0009523C
		protected override void Dispose(bool disposing)
		{
			bool flag = disposing && this.components != null;
			if (flag)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		/// <summary> 
		/// 设计器支持所需的方法 - 不要修改
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		// Token: 0x06001F18 RID: 7960 RVA: 0x00097074 File Offset: 0x00095274
		private void InitializeComponent()
		{
			base.SuspendLayout();
			base.AutoScaleDimensions = new SizeF(7f, 17f);
			base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.Transparent;
			this.Cursor = Cursors.Hand;
			this.Font = new Font("微软雅黑", 9f, FontStyle.Regular, GraphicsUnit.Point, 134);
			base.Margin = new Padding(3, 4, 3, 4);
			base.Name = "UserSwitch";
			base.Size = new Size(214, 207);
			base.Load += this.UserSwitch_Load;
			base.Click += this.UserSwitch_Click;
			base.Paint += this.UserSwitch_Paint;
			base.ResumeLayout(false);
		}

		// Token: 0x04000713 RID: 1811
		private Color color_switch_background = Color.DimGray;

		// Token: 0x04000714 RID: 1812
		private Brush brush_switch_background = null;

		// Token: 0x04000715 RID: 1813
		private Pen pen_switch_background = null;

		// Token: 0x04000716 RID: 1814
		private bool switch_status = false;

		// Token: 0x04000717 RID: 1815
		private Color color_switch_foreground = Color.FromArgb(36, 36, 36);

		// Token: 0x04000718 RID: 1816
		private Brush brush_switch_foreground = null;

		// Token: 0x04000719 RID: 1817
		private StringFormat centerFormat = null;

		// Token: 0x0400071A RID: 1818
		private string[] description = new string[]
		{
			"Off",
			"On"
		};

		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		// Token: 0x0400071C RID: 1820
		private IContainer components = null;
	}
}
